<!-- 会议页面 -->
<template>
	<view class="context">
		<!-- 标题和会议内容 -->
		<!-- 展示模式 -->
		<view class="meetingRoughly" v-if="!meetingtitleShow">
			<view class="title">
				<text>周一部门例会</text>
				<view class="tag">
					<u-tag :text="status" plain size="mini" :type="tag" />
				</view>
			</view>
			<!-- 会议内容 -->
			<view class="info-box">
				<view class="temp"></view>
				<scroll-view scroll-y class="scroll-info">
					<view class="info">
						<text class="textarea">{{ textarea }}</text>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 输入模式 -->
		<view class="meetingRoughly" v-if="meetingtitleShow">
			<view class="title">
				<textarea
					class="textareaTitle"
					v-model="ScheduledTitle"
					placeholder="会议预定"
					placeholder-class="textarea-placeholder"/>
			</view>
			<!-- 会议内容 -->
			<view class="info-box">
				<!-- <view class="temp"></view> -->
				<view class="land"></view>
				<scroll-view scroll-y class="scroll-info">
					<view class="info">
						<textarea
						class="textareaText"
						v-model="ScheduledText"
						placeholder="会议内容补充"
						placeholder-class="textarea-placeholder"/>
					</view>
				</scroll-view>
			</view>
		</view>
		<!-- 会议生命周期为: 待审核 已退回 待开始 进行中 以结束 以取消 -->
		<!-- 会议时间 -->
    <chooseTime></chooseTime>
		<!-- 会议室 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="会议室" type="local" :local="meetingRoomInfo"></list>
		<!-- 参会码 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="参会码" type="text" text="点击查看"
			@child-clicked="meetingCode" v-if="showCode"></list>
		<!-- 参会人 -->
		<choose-persion></choose-persion>
		<!-- 签到记录 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="签到记录" type="icon" v-if="signInShow"
			iconTwo="/static/allMeetingIcos/time.svg" @child-clicked="signIn"></list>
		<!-- 会议纪要 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="会议纪要" type="icon" v-if="minutesShow"
			iconTwo="/static/allMeetingIcos/time.svg" @child-clicked="minutes"></list>
		<!-- 附件 -->
		<view class="annex">
			<list iconPath="/static/allMeetingIcos/time.svg" message="附件" type="text" text="上传至附件文档"
				@child-clicked="uploadAttachments"></list>
			<!-- 附件显示组件 -->
			<annex :informationArry="infoArr" v-if="infoArr.length != 0" />
			<view v-else class="noAttachments">还未有附件</view>
		</view>
		<!-- 会议提醒 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="会议提醒" type="text" :text="timeTip" v-if="RemindShow" @child-clicked="openRemindShow"></list>
		<u-popup :show="popup" mode="bottom" round="14" @close="closeRemindShow">
			<view class="popupListTime">
				<view @click="chooseTip(1)">开始时</view>
				<view @click="chooseTip(2)">5分钟前</view>
				<view @click="chooseTip(3)">15分钟前</view>
				<view @click="chooseTip(4)">30分钟前</view>
			</view>
		</u-popup>
		<!-- 提醒方式 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="提醒方式" type="text" :text="timeTipType" v-if="RemindShow" @child-clicked="popup2 = true"></list>
    <u-popup :show="popup2" mode="bottom" round="14" @close="closeRemindShow">
      <view class="popupListTime">
        <view @click="reminderMethod(1)">客户端</view>
        <view @click="reminderMethod(2)">短信</view>
        <view @click="reminderMethod(3)">邮件</view>
      </view>
    </u-popup>
		<!-- 审核人 -->
		<list iconPath="/static/allMeetingIcos/time.svg" message="审核人" type="text" text="刘" v-if="refundedPerson"></list>
		<view class="refunded" v-if="refundedInfo">退回原因: 手续不全</view>
		<!-- 编辑 -->
		<view class="compilation" v-if="showSub" style="" @click="subMeeting">预约</view>
		<view class="compilation" v-if="showCompilation">编辑</view>
		<view class="compilation" style="color: red;" @click="deleteMeeting" v-if="showCompilation">删除</view>
		<!-- 空间占位 -->
		<view style="height: 100rpx; width: 100%;"></view>
	</view>
</template>

<script>
	import list from './component/list.vue';
	import annex from './component/annex.vue';
  import {
    request
  } from '../../utils/request'
	import timeUtil from '../../utils/timeUtil';
	import chooseTime from './component/chooseTime.vue';
  import choosePersion from "@/pages/meeting/component/choosePersion.vue";
	export default {
		data() {
			return {
				/*   
					赋值区域
				*/
				meetingID: '',//会议id号
        meetingRoomInfo:'',//会议室基本信息
				ScheduledTitle:'',//输入标题
				ScheduledText:'',//输入文本详情
				textarea: '会议内容\n1、部门本周工作目标\n2、部门个人工作进度汇报\n3、公司年会活动讨论\n4、公司年会活动\n5、公司年会活动',
				//tag详细请见 https://uviewui.com/components/tag.html (uView)
				tag: 'warning', //标签类型 可选值:success/info/warning/error
				LifeCycle: 'Input',//周期值
				infoArr: [], //会议资料名称,
        filePath:'',//附件地址，
        timeTip: '开始前',
        timeTipType: '客户端',
        timeTipNum: 0,
        timeTipTypeNum: 0,
				infoArr: ['活动照片.jpg','活动照片.jpg','活动照片.jpg','活动照片.jpg'],//会议资料名称
				/*   
					布尔类型区域
				*/
				meetingtitleShow: false,//输入框
				showTime: false, //显示选择器
				showTime2: false, //显示
				minutesShow:false,//会议纪要
				signInShow: false,//会议签到
				showCode: false, // 二维码选项
				showCompilation: false, // 编辑选项
				showSub:false,//预约选项
				refundedInfo: false,//退回原因显示
				refundedPerson: false,//审核人
				RemindShow:true,//提醒方式展示
				popup: false,//会议提醒弹出
        popup2: false,//会议提醒方式弹出
			}
		},
		
		methods: {
			//跳转二维码页面
			meetingCode() {
				uni.navigateTo({
					url: '/pages/attendanceCode/attendanceCode'
				});
			},
			//跳转会议纪要页面
			minutes() {
				uni.navigateTo({
					url: '/pages/minute/minute'
				});
			},
			//跳转会议签到记录页面
			signIn() {
				uni.navigateTo({
					url: '/pages/signIn/signIn'
				});
			},
			//取消会议
			deleteMeeting() {
				uni.showModal({
					title: '取消会议',
					content: '取消后会议室将被释放，会议取消通知将发送至相关人员，确定取消吗？',
					success: function(res) {
						if (res.confirm) {
							//删除会议接口
							//TODO
						}
					}
				})
			},
			openRemindShow(){//开启提醒选项
				this.popup = true;
			},
			closeRemindShow(){//关闭提醒选项
				this.popup = false;
				this.showTime2 = false;
			},
			//上传附件函数
			uploadAttachments() {
				//uniapp条件编译
				//异步回调
				let file = new Promise((resolve, reject) => {
					try {
						uni.chooseFile({
							//获取成功
							success: (res) => {
								resolve(res);
							},
							//获取失败
							fail: () => {}
						});
					} catch (e) {
						//微信Api(微信uniapp此api不兼容微信)
						wx.chooseMessageFile({
							success: (res) => {
								resolve(res);
							},
							//获取失败
							fail: () => {}
						})
					}
				});
				//回调步骤
				file.then((res) => {
					//上传至服务器接口
          let filePath = res.tempFiles[0].path
          let result = request.upFile({
              file: filePath,
              Username: uni.getStorageSync('UserInfo').username,
              UserID: uni.getStorageSync('UserInfo').userid,
              MeetingID: this.meetingID
          });
          result.then((res)=>{
            console.log(res);
            //反馈
            uni.showToast({
              title: '上传成功',
              duration: 2000
            });
          }).catch((res)=>{
          });
				});
			},
      //选择提示时间	
      chooseTip(select){
        switch (select){
          case 1:
            this.timeTip = '开始前';
            break;
          case 2:
            this.timeTip = '5分钟';
            break;
          case 3:
            this.timeTip = '15分钟';
            break;
          case 4:
            this.timeTip = '30分钟';
            break;
        }
        this.timeTipNum = select;
        this.popup = false;
      },
      //选择提醒方式
      reminderMethod(select){
        switch (select){
          case 1:
            this.timeTipType = '客户端';
            break;
          case 2:
            this.timeTipType = '短信';
            break;
          case 3:
            this.timeTipType = '邮件';
            break;
        }
        this.timeTipTypeNum = select;
        this.popup2 = false;
      },
			//提交会议接口
			subMeeting(){
				//判断生命周期状态
				if(!(this.LifeCycle === 'Input')){return;}
        let sub = request.subinfo({
					MeetingName: this.ScheduledTitle,//输入标题
					MeetingDetails: this.ScheduledText,//输入文本详情
					MeetingBeginTime: uni.getStorageSync('Time')[0],//时间戳 1
					MeetingEndTime: uni.getStorageSync('Time')[1],//时间戳 2
					MeetingRoomID: this.meetingID,//会议室 ID
					MeetingAttendeeIDs:[],
					MeetingRemindID:this.timeTipNum,
					MeetingRemindTypeID:this.timeTipTypeNum,
					MeetingSubmitterID: uni.getStorageSync('UserInfo').userid //myself send message
				});
        sub.then((res)=>{
          console.log(res)
        })
			},
			//会议生命周期函数
			meetingLifeCycle() {
				//会议生命周期为: 待审核 已退回 待开始 进行中 以结束 以取消
				switch (this.LifeCycle) {
					case 'Not-Reviewed': {
						this.status = '待审核'
						this.tag = 'warning'
						this.refundedPerson = true
						this.showCompilation = true
					}
					break;
					case 'Refunded': {
						this.status = '已退回'
						this.tag = 'info'
						this.refundedInfo = true
						this.refundedPerson = true
					}
					case 'Not-Start': {
						this.status = '未开始'
						this.tag = 'primary'
						this.showCode = true
						this.showCompilation = true
					}
					break;
					case 'Ongoing': {
						this.status = '进行中'
						this.tag = 'success'
						this.showCode = true
						this.minutesShow = true
						this.signInShow = true
					}
					break;
					case 'End': {
						this.status = '已结束'
						this.tag = 'info'
						this.minutesShow = true
						this.RemindShow = false
					}
					break;
					case 'Cancel': {
						this.status = '已取消'
						this.tag = 'info'
						this.minutesShow = true
					}
					break;
					case 'Input': {//输入模式(特例)
						this.meetingtitleShow = true
						this.showSub = true
            this.showCompilation = false;
					}
					break;
				}
			},
      //渲染主页 -> 会议页面
      showMeetingInfo(){
        //获取到主页信息
        let info = uni.getStorageSync('Index-Information',info);
        //TODO 拿到数据渲染页面
        if(info.MeetingStatus === 1) this.LifeCycle = 'Not-Start'
        //刷新周期
        this.meetingLifeCycle()
      },
			onLoad(options) {
    			// 使用 options.id 获取传递过来的参数
				// 赋予生命周期声明输入模式
				this.LifeCycle = options.LifeCycle
        console.log(this.LifeCycle)
				this.meetingID = options.id;
        this.meetingRoomInfo = options.MeetingRoomName +"-"+ options.MeetingRoomLocation
				this.meetingLifeCycle(); 
  			},
		},
		created() {
				//判断会议状态
      setInterval(()=>{this.meetingLifeCycle();},1000)
      this.showMeetingInfo()
		}, 
		
		components: {
			list,
			annex,
      chooseTime,
      choosePersion
		}
	}
</script>

<style>
	@import 'meeting.css';
</style>